const app = getApp();
import {marketRecord,delMarketRecord} from "../../../config/api";
import util from "../../../utils/util";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:1,
    limit:10000000,
    isEmpty:false,//是否显示暂无数据默认不显示
    list: [],//集市记录

  },

  //获取集市记录
  getMarketList(){
     let that = this;
     let member = wx.getStorageSync('member');
     if(!member){
       that.setData({
         isEmpty:true
       });
       return;
     }
     let params = {
      page:that.data.page,
      limit:that.data.limit,
      vollege_id:app.globalData.vollege_id,
      idcard:member.idcard,
    };
    util.apiRequest(marketRecord,params,null).then(r=>{
      console.log('集市记录：',r.data.data);
      that.setData({
        list:r.data.data
      });
      if(r.data.data.length==0){
        that.setData({
          isEmpty:true
        });
      }else{
        that.setData({
          isEmpty:false
        });
      }

    });

  },

 //  图片预览
 previewImg(e){
  let that = this;
  console.log('e.currentTarget.dataset.img:',e.currentTarget.dataset);
  wx.previewImage(
    {
      current: e.currentTarget.dataset.img,
      urls: e.currentTarget.dataset.imgs
    }
  );
},

//删除记录
delMarketRecord(e){
  let that = this;
  console.log('删除记录e:',e.currentTarget.dataset.item);
  let item = e.currentTarget.dataset.item;
  wx.showModal({
    title: '提示',
    content: '您确认删除该记录吗？',
    success (res) {
      if (res.confirm) {
        console.log('用户点击确定');
        util.apiRequest(delMarketRecord,{id:item.id},null).then(r=>{
          console.log('删除结果为：',r.data.info);
          wx.showToast({
            title: r.data.info,
            icon: 'loading',
            duration: 2000
          })
          that.getMarketList();
        });
      } else if (res.cancel) {
        console.log('用户点击取消')
      }
    }
  })
},



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     this.getMarketList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})